﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel;

namespace Library.Web.Models
{
	public class RequestBook : IDataErrorInfo
	{
		[Required(ErrorMessage = "Please enter book title")]
		[DisplayName("Book title")]
		public string BookTitle { get; set; }

		[DisplayName("Authors")]
		public string BookAuthors { get; set; }

		[Required(ErrorMessage = "Please enter your reason for ordering this book")]
		[DisplayName("Your reason for order")]
		[StringLength(200, MinimumLength = 10, ErrorMessage = "Please give us a strong reason !")]
		public string Reason { get; set; }

		[DisplayName("Url with a short description")]
		[Required(ErrorMessage = "Please provide us a link for this book")]
		public string UrlToBook { get; set; }

		public string Error
		{
			get
			{
				return null;
			}
		}

		public string this[string columnName]
		{
			get
			{
				if (columnName == "UrlToBook")
				{
					if (!string.IsNullOrEmpty(UrlToBook) && !UrlToBook.Contains("http"))
					{
						return "Please enter a valid Url. Must start with http";
					}
				}

				return null;
			}
		}
	}
}